using System;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using System.Drawing.Printing;

namespace qPrintComponent
{
    [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
    [SecurityPermission(SecurityAction.Demand,Unrestricted = true)]
    internal struct qPrinterDefaults
    {
        [MarshalAs(UnmanagedType.SysInt)]
        private IntPtr dDataType;
        [MarshalAs(UnmanagedType.SysInt)]
        private IntPtr dDeviceMode;
        [MarshalAs(UnmanagedType.U4)]
        public int DesiredAccess ;
        
        internal qPrinterDefaults(bool AllAccess)
        {
            const int PRINTER_ACCESS_ADMINISTER = 0x4;
            const int PRINTER_ACCESS_USE = 0x8;
            const int STANDARD_RIGHTS_REQUIRED = 0xF0000;
            const int PRINTER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED | PRINTER_ACCESS_ADMINISTER | PRINTER_ACCESS_USE);
            this.dDataType = IntPtr.Zero;
            this.dDeviceMode = IntPtr.Zero;
            if (AllAccess)
            {
                new PrintingPermission(PermissionState.Unrestricted).Demand();
                this.DesiredAccess = (int)PRINTER_ALL_ACCESS;
            }
            else this.DesiredAccess = (int)PRINTER_ACCESS_USE;
        }
    }
}